﻿@model EM.OA.Portal.Models.WFFlowConfigModels
@{
    Layout = "~/Views/Shared/_LayoutContent.cshtml";
}
@*工作流分类管理*@
<script type="text/javascript" src="~/Scripts/page/WorkFlow/WFFlowConfig.js"></script>

<div class="easyui-layout" style="height: 500px;">

    @*tree*@
    <div data-options="region:'west',split:true" title="工作流列表" style="width: 400px;">
        @*list*@
        <table id="list" class="easyui-datagrid" toolbar="#toolbar">
        </table>
        <div id="toolbar">
            <table>
                <tr>
                    <td colspan="3">
                        <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="add()">增加</a>
                        <a href="#" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="edit()">修改</a>
                        <a href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="del()">删除</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div style="width: 2px"></div>
    @*list*@
    <div data-options="region:'center',title:'工作流明细'">

        <form id="fm" method="post">
            @Html.HiddenFor(m => m.FlowConfigID)
            <div>
                @Html.LabelFor(m => m.FlowKind)
                @Html.DropDownListFor(m => m.FlowKind, new EM.OA.Portal.Models.WorkPlanModels().GetListItems2("WorkFlowKind"), new { @class = "easyui-combobox" })
            </div>
            <div>
                @Html.LabelFor(m => m.FlowConfigName)
                <input name="FlowConfigName" class="easyui-validatebox" data-options="required:true,validType:'length[1,200]'">
            </div>
            <br />
            <div id="div_Detail" style="display: none">
                <!--工作流明细设置 -->
                @Html.LabelFor(m => m.StepName)
                <input name="StepName" class="easyui-validatebox" data-options="validType:'length[1,200]'" />
                @Html.LabelFor(m => m.ApprovalUserID)
                <input name="ApprovalUserID" id="ApprovalUserID" type="hidden" />
                @Html.Partial("~/Views/Shared/_UserListPartial.cshtml")
                <a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="addDetail()">添加级别</a>
                <table id="listDetail" class="easyui-datagrid" toolbar="#toolbarDetail">
                </table>
                <div id="toolbarDetail">
                    <a href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="delDetail()">删除</a>
                </div>
            </div>
        </form>

        <div>
            <a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="save()">保存</a>
            <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
        </div>
    </div>
</div>

<script type="text/javascript">
    function loadConfigDetail() {
        var flowConfigID = $('#FlowConfigID').val();
        var querData = {
            j_flowConfigID: flowConfigID,
        };
        loadDetail(querData);
    }


    function addDetail() {
        $('#ApprovalUserID').val($("#txt_UserID").val());
        $('#fm').form('submit', {
            url: 'WFFlowConfig/AddDetail',
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (result) {
                if (result == 'OK') {
                    loadConfigDetail();
                    $('#listDetail').datagrid('reload');    // reload the user data  
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result
                    });
                }
            }
        });
    }

    function loadDetail(queryData) {
        $('#listDetail').datagrid({
            title: '工作流程设置明细表',
            idField: 'FlowConfigDetailID',
            fitColumns: 'true',
            autoRowHeight: true,
            nowrap: true,
            striped: true,
            pagination: false,
            url: '/WFFlowConfig/GetListDetail',
            queryParams: queryData,    //参数为了多条件查询预留
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'FlowConfigDetailID', title: 'ID', hidden: true },
                { field: 'FlowConfigID', title: '流程ID', width: 180, hidden: true },
                { field: 'StepLevel', title: '步骤级别', width: 180 },
                { field: 'StepName', title: '步骤名称', width: 180 },
                { field: 'ApprovalUserID', title: '审批人', width: 180, hidden: true },
                { field: 'NextApprovalUserName', title: '审批人', width: 180 },
                { field: 'ApprovalRoleID', title: '如果角色下有两个人，只走第一个人', width: 180, hidden: true },
                { field: 'CCUserIDs', title: '抄送人', width: 180, hidden: true },
                { field: 'CCDepartmentIDs', title: '抄送部门', width: 180, hidden: true }

            ]],
        });
    }

    function delDetail() {
        var rows = $('#listDetail').datagrid('getSelected');
        if (rows) {
            $.messager.confirm(delDlgTitle, delDlgMsg, function (r) {
                if (r) {
                    $.post('/WFFlowConfigDetail/Delete', { id: rows.FlowConfigDetailID },
                        function (result) {
                            if (result == 'OK') {
                                $("#listDetail").datagrid('clearSelections');
                                $('#listDetail').datagrid('reload');    // reload the user data  
                            } else {
                                $.messager.show({   // show error message  
                                    title: 'Error',
                                    msg: result
                                });
                            }
                        });
                }
            });
        }
    }
</script>
